package com.ftg.shopping.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.user.entity.sp_userinfo;
import com.ftg.shopping.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "登录管理")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("查看登录数据")
    @GetMapping("/list")
    public List<sp_userinfo> list(){
        return userService.list();
    }

    @ApiOperation("按主键查看一个用户")
    @PutMapping("/findone/{userid}")
    public sp_userinfo list(@ApiParam("主键")@PathVariable int userid){
        return userService.findone(userid);
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public LayuiPage<sp_userinfo> login(sp_userinfo s){
        return userService.login(s);
    }


    @ApiOperation("分页查询无模糊")
    @GetMapping("/page")
    public IPage<sp_userinfo> list(@RequestParam int page, @RequestParam int limit){
        return userService.testPage(page,limit);
    }

    @ApiOperation("分页查询带模糊")
    @GetMapping("/page1")
    public IPage<sp_userinfo> list1(@RequestParam int page, @RequestParam int limit, @RequestParam(required = false) String username){
        return userService.testPage1(page,limit,username);
    }


    @ApiOperation("分页查询无模糊")
    @DeleteMapping("/del/{ids}")
    public int delList(@PathVariable List<Integer> ids){
        return userService.delDeptIds(ids);
    }

    @ApiOperation("layui分页")
    @GetMapping("/page2")
    public LayuiPage<sp_userinfo> page2(@RequestParam int page, @RequestParam int limit){
        return userService.testPage2(page,limit);
    }

    @ApiOperation("更改操作")
    @PostMapping("/update")
    public int update(@RequestBody sp_userinfo u){
        return userService.updateDept(u);
    }


}
